/*
 * @Author: xiaosihan 
 * @Date: 2023-03-05 17:31:25 
 * @Last Modified by: xiaosihan
 * @Last Modified time: 2024-10-30 15:01:59
 */

import { flatten, get, isNumber, round } from "lodash";
import { autorun, toJS } from "mobx";
import { Box3, BufferAttribute, BufferGeometry, DoubleSide, Group, Mesh, MeshBasicMaterial, PlaneGeometry, Shape, ShapeGeometry, Vector3 } from "three";
import * as BufferGeometryUtils from 'three/examples/jsm/utils/BufferGeometryUtils.js';
import { degToRad } from "three/src/math/MathUtils";
import rockMapPNG from "./rockMap.png";
import geometryJSON from "./sichuan.json";
import mapPNG from "./sichuan_map.png";
import ExtrudeMesh, { ExtrudeMeshProps } from "three-base/ExtrudeMesh";
import threeLoader from "three-base/threeLoader";
import threeUtils from "three-base/threeUtils";
import keyContorls from "three-base/keyContorls";

import { Line2 } from "three/examples/jsm/lines/Line2.js";
import { LineGeometry } from "three/examples/jsm/lines/LineGeometry.js";
import { LineMaterial } from "three/examples/jsm/lines/LineMaterial.js";
import AreaName1 from "../AreaName1/AreaName1";
import AreaName3 from "../AreaName3/AreaName3";
import Ball from "../Ball/Ball";
import RingSprite from "../RingSprite/RingSprite";
import chengdu_mapPNG from "../SiChuanMap/chengdu_map.png";
import siChuanMap3DStore from "../chengduMap3DStore";
import axios from "axios";
import doubtfulSituationStore from "@views/DoubtfulSituation/doubtfulSituationStore";


// 四川地图
export default class SichuanMap extends Group {

    constructor() {
        super();
    }

    //成都地图
    chengduMesh = (() => {
        const planGeo = new PlaneGeometry(15.35, 10, 1, 1);
        planGeo.rotateX(degToRad(-90));
        const chengduMaterial = new MeshBasicMaterial({
            color: "#47b1ff",
            map: threeLoader.getTexture(chengdu_mapPNG)
        });
        const chengduMesh = new Mesh<any, any>(planGeo, chengduMaterial);

        chengduMesh.position.set(0.981, 0.521, -0.575);

        //three事件
        // chengduMesh.userData = {
        //     cursor: "pointer",
        //     enableEvent: true
        // };
        // chengduMesh.addEventListener("click", e => {
        //     console.log(e.point);
        // });

        autorun(() => {
            const { areaCode } = siChuanMap3DStore;
            chengduMesh.visible = (510100 === areaCode);
        });

        this.add(chengduMesh);
        return chengduMesh;
    })();

    //凉山地图
    liangshanMesh = (() => {
        const planGeo = new PlaneGeometry(15.35, 10, 1, 1);
        planGeo.rotateX(degToRad(-90));
        const chengduMaterial = new MeshBasicMaterial({
            color: "#47b1ff",
            map: threeLoader.getTexture(chengdu_mapPNG)
        });
        const liangshanMesh = new Mesh<any, any>(planGeo, chengduMaterial);

        liangshanMesh.position.set(-0.986, 0.521, 2.525);

        // //three事件
        // liangshanMesh.userData = {
        //     cursor: "pointer",
        //     enableEvent: true
        // };
        // liangshanMesh.addEventListener("click", e => {
        //     //@ts-ignore
        //     console.log(e.point);
        // });

        autorun(() => {
            const { areaCode } = siChuanMap3DStore;
            liangshanMesh.visible = (513400 === areaCode);
        });

        this.add(liangshanMesh);
        return liangshanMesh;
    })();

    //甘孜地图
    ganziMesh = (() => {
        const planGeo = new PlaneGeometry(15.35, 10, 1, 1);
        planGeo.rotateX(degToRad(-90));
        const chengduMaterial = new MeshBasicMaterial({
            color: "#47b1ff",
            map: threeLoader.getTexture(chengdu_mapPNG)
        });
        const ganziMesh = new Mesh<any, any>(planGeo, chengduMaterial);

        ganziMesh.position.set(-3.029, 0.521, -0.909);

        // // three事件
        // ganziMesh.userData = {
        //     cursor: "pointer",
        //     enableEvent: true
        // };
        // ganziMesh.addEventListener("click", e => {
        //     //@ts-ignore
        //     console.log(e.point.toArray().map(v => round(v, 3)).join(", "));
        // });


        autorun(() => {
            const { areaCode } = siChuanMap3DStore;
            ganziMesh.visible = (513300 === areaCode);
        });

        this.add(ganziMesh);
        return ganziMesh;
    })();

    // 阿坝地图
    abaMesh = (() => {
        const planGeo = new PlaneGeometry(15.35, 10, 1, 1);
        planGeo.rotateX(degToRad(-90));
        const chengduMaterial = new MeshBasicMaterial({
            color: "#47b1ff",
            map: threeLoader.getTexture(chengdu_mapPNG)
        });
        const abaMesh = new Mesh<any, any>(planGeo, chengduMaterial);

        abaMesh.position.set(-0.464, 0.521, -2.281);

        // three事件
        abaMesh.userData = {
            cursor: "pointer",
            enableEvent: true
        };
        abaMesh.addEventListener("click", e => {
            //@ts-ignore
            console.log(e.point.toArray().map(v => round(v, 3)).join(", "));
        });

        autorun(() => {
            const { areaCode } = siChuanMap3DStore;
            abaMesh.visible = (513200 === areaCode);
        });

        this.add(abaMesh);
        return abaMesh;
    })();

    // 地图面模型材质
    sideMaterial = new MeshBasicMaterial({
        color: "#47b1ff",
        map: threeLoader.getTexture(mapPNG),
        side: DoubleSide
    });

    // 地图面模型
    sideGroup = (() => {
        const sideGroup = new class SideGroup extends Group { }();

        geometryJSON.features.map((f, index) => {
            const { adcode, name } = f.properties;
            let { coordinates, type } = f.geometry;

            let points: number[][][] = [];
            if (type === 'MultiPolygon') {
            }

            if (!isNumber(get(coordinates, [0, 0, 0]))) {
                points.push(...flatten(coordinates));
            }

            let geometrys: Array<BufferGeometry> = [];

            for (let i = 0; i < points.length; i++) {
                let shape = new Shape();
                for (let ii = 0; ii < points[i].length; ii++) {
                    const [x, y] = points[i][ii];
                    if (ii === 0) {
                        shape.moveTo(x, y);
                    } else {
                        shape.lineTo(x, y);
                    }
                }

                geometrys.push(new ShapeGeometry(shape));
            }

            let geometry = BufferGeometryUtils.mergeGeometries(geometrys);

            geometry.rotateX(degToRad(-90));

            // 每一个区的模型对象
            const areaMesh = new Mesh(geometry, this.sideMaterial.clone());

            // autorun(() => {
            // const { areaCode } = bigScreenStore;
            // areaMesh.material.map =
            //     areaCode === "100000"
            //         ? threeLoader.getTexture(chinaMap2PNG)
            //         : threeLoader.getTexture(chinatMap2ActivePNG);
            // areaMesh.material.opacity =
            //     areaCode === "100000" || code === areaCode ? 1 : 0.7;
            // areaMesh.material.needsUpdate = true;
            // });

            // autorun(() => {
            //     const { areaCode } = siChuanMap3DStore;
            //     const visible = [510000, adcode].includes(areaCode);
            //     areaMesh.visible = visible;
            // });

            areaMesh.userData = { name, adcode };
            areaMesh.name = name;

            if ([510100].includes(adcode)) {
                // 成都模型
                Object.assign(areaMesh.userData, { cursor: "pointer" });
                areaMesh.addEventListener("click", e => {
                    siChuanMap3DStore.setAreaCode(adcode);
                    //请求成都的机构数据
                    axios.get("./intelligent_check/map_data_chengdu.json").then(res => {
                        const map_data = res.data;
                        doubtfulSituationStore.setMap_data(map_data);
                        doubtfulSituationStore.setActiveMap(map_data[0]);
                    });
                });

                const chengduGeo = areaMesh.geometry.clone();
                chengduGeo.center();
                const size = threeUtils.getSize(chengduGeo);
                const center = threeUtils.getCenter(chengduGeo);
                const sideLength = Math.max(size.x, size.z);

                const position = chengduGeo.getAttribute("position") as BufferAttribute;
                const uv = chengduGeo.getAttribute("uv") as BufferAttribute;

                for (let i = 0; i < position.count; i++) {
                    uv.setX(i, (position.getX(i) + sideLength / 2) / sideLength);
                    uv.setY(i, 1 - (position.getZ(i) + sideLength / 2) / sideLength);
                }
                chengduGeo.setAttribute("uv", uv);

                this.chengduMesh.geometry = chengduGeo;
                threeUtils.addWork(() => {
                    const center = threeUtils.getCenter(areaMesh);
                    this.chengduMesh.position.copy(center);
                    this.chengduMesh.position.setY(0.5);
                });

            } else if ([513400].includes(adcode)) {
                // 凉山地图
                Object.assign(areaMesh.userData, { cursor: "pointer" });
                areaMesh.addEventListener("click", e => {
                    siChuanMap3DStore.setAreaCode(adcode);
                    //请求凉山的机构数据
                    axios.get("./intelligent_check/map_data_liangshan.json").then(res => {
                        const map_data = res.data;
                        doubtfulSituationStore.setMap_data(map_data);
                        doubtfulSituationStore.setActiveMap(map_data[0]);
                    });
                });

                const liangshanGeo = areaMesh.geometry.clone();
                liangshanGeo.center();
                const size = threeUtils.getSize(liangshanGeo);

                const sideLength = Math.max(size.x, size.z);

                const position = liangshanGeo.getAttribute("position") as BufferAttribute;
                const uv = liangshanGeo.getAttribute("uv") as BufferAttribute;

                for (let i = 0; i < position.count; i++) {
                    uv.setX(i, (position.getX(i) + sideLength / 2) / sideLength);
                    uv.setY(i, 1 - (position.getZ(i) + sideLength / 2) / sideLength);
                }
                liangshanGeo.setAttribute("uv", uv);

                this.liangshanMesh.geometry = liangshanGeo;

                threeUtils.addWork(() => {
                    const center = threeUtils.getCenter(areaMesh);
                    this.liangshanMesh.position.copy(center);
                    this.liangshanMesh.position.setY(0.5);
                });

            } else if ([513300].includes(adcode)) {
                // 甘孜地图
                Object.assign(areaMesh.userData, { cursor: "pointer" });
                areaMesh.addEventListener("click", e => {
                    siChuanMap3DStore.setAreaCode(adcode);
                    //请求凉山的机构数据
                    axios.get("./intelligent_check/map_data_ganzi.json").then(res => {
                        const map_data = res.data;
                        doubtfulSituationStore.setMap_data(map_data);
                        doubtfulSituationStore.setActiveMap(map_data[0]);
                    });
                });

                const ganziGeo = areaMesh.geometry.clone();
                ganziGeo.center();
                const size = threeUtils.getSize(ganziGeo);
                const center = threeUtils.getCenter(ganziGeo);
                const sideLength = Math.max(size.x, size.z);

                const position = ganziGeo.getAttribute("position") as BufferAttribute;
                const uv = ganziGeo.getAttribute("uv") as BufferAttribute;

                for (let i = 0; i < position.count; i++) {
                    uv.setX(i, (position.getX(i) + sideLength / 2) / sideLength);
                    uv.setY(i, 1 - (position.getZ(i) + sideLength / 2) / sideLength);
                }
                ganziGeo.setAttribute("uv", uv);

                this.ganziMesh.geometry = ganziGeo;

                threeUtils.addWork(() => {
                    const center = threeUtils.getCenter(areaMesh);
                    this.ganziMesh.position.copy(center);
                    this.ganziMesh.position.setY(0.5);
                });

            } else if ([513200].includes(adcode)) {
                // 阿坝地图
                Object.assign(areaMesh.userData, { cursor: "pointer" });
                areaMesh.addEventListener("click", e => {
                    siChuanMap3DStore.setAreaCode(adcode);
                    //请求凉山的机构数据
                    axios.get("./intelligent_check/map_data_aba.json").then(res => {
                        const map_data = res.data;
                        doubtfulSituationStore.setMap_data(map_data);
                        doubtfulSituationStore.setActiveMap(map_data[0]);
                    });
                });

                const abaGeo = areaMesh.geometry.clone();
                abaGeo.center();
                const size = threeUtils.getSize(abaGeo);
                const center = threeUtils.getCenter(abaGeo);
                const sideLength = Math.max(size.x, size.z);

                const position = abaGeo.getAttribute("position") as BufferAttribute;
                const uv = abaGeo.getAttribute("uv") as BufferAttribute;

                for (let i = 0; i < position.count; i++) {
                    uv.setX(i, (position.getX(i) + sideLength / 2) / sideLength);
                    uv.setY(i, 1 - (position.getZ(i) + sideLength / 2) / sideLength);
                }
                abaGeo.setAttribute("uv", uv);

                this.abaMesh.geometry = abaGeo;

                threeUtils.addWork(() => {
                    const center = threeUtils.getCenter(areaMesh);
                    this.abaMesh.position.copy(center);
                    this.abaMesh.position.setY(0.5);
                });

            }



            // areaMesh.addEventListener("mouseenter", e => {
            //     homeStore.setHoverAreaName(f.properties.name);
            //     homeStore.setHoverAreaOpacity(1);
            // });
            // areaMesh.addEventListener("mouseleave", e => {
            //     homeStore.setHoverAreaName("");
            //     homeStore.setHoverAreaOpacity(0);
            // });
            // areaMesh.addEventListener("mousemove", e => {
            //     homeStore.setHoverAreaPosition(e.x, e.y);
            // });

            sideGroup.add(areaMesh);
        });


        // 计算每个模型的uv的值, 并移动到中心点
        const box3 = new Box3();
        const center = new Vector3();
        const size = new Vector3();
        box3.setFromObject(sideGroup);
        box3.getSize(size);
        box3.getCenter(center);
        const sideLength = Math.max(size.x, size.z);

        sideGroup.traverse(obj => {
            let mesh = obj as Mesh;
            if (mesh.isMesh) {
                mesh.geometry.translate(-center.x, -center.y, -center.z);

                const position = mesh.geometry.getAttribute("position") as BufferAttribute;
                const uv = mesh.geometry.getAttribute("uv") as BufferAttribute;

                for (let i = 0; i < position.count; i++) {
                    uv.setX(i, (position.getX(i) + sideLength / 2) / sideLength);
                    uv.setY(i, 1 - (position.getZ(i) + sideLength / 2) / sideLength);
                }
                mesh.geometry.setAttribute("uv", uv);
            }
        });

        autorun(() => {
            const { areaCode } = siChuanMap3DStore;
            const visible = [510000].includes(areaCode);
            sideGroup.visible = visible;
        });

        // threeUtils.scaleTo(sideGroup, 10);
        threeUtils.centerObject3D(sideGroup);
        sideGroup.position.set(0, 0.5, 0);

        this.add(sideGroup);
        return sideGroup;
    })();

    // 岩石层材质
    rockMaterial = new MeshBasicMaterial({
        color: "#fff",
        side: DoubleSide,
        map: threeLoader.getTexture(rockMapPNG)
    });

    //每块地图独立添加岩石层
    rockGroup = (() => {
        const rockGroup = new class RockGroup extends Group { }();

        // 更具选中的样式
        autorun(() => {
            // const { areaCode } = I3401L01Store;
            // material.opacity = (areaCode === "370000") ? 1.0 : 0.5;
            // plane.constant = areaCode === "370000" ? 2 : -1;
            // rockGroup.children.map(mesh => {
            //     mesh.visible = ["370000", mesh.uuid].includes(areaCode);
            // });
        });

        // 岩层成挤出路径
        const rockMeshoptions: ExtrudeMeshProps = {
            paths: [
                // { vector3: [-304, 0.1, 250], radius: 1, segments: 1, scale: { x: 1, y: 1 }, name: "" },
            ],
            shapePath: [
                [0, -5],
                [0, 5]
            ],
            closed: true
        };

        // 提取每个区的地图轮廓
        geometryJSON.features.map((f, index) => {
            const { adcode, name } = f.properties;
            let { coordinates, type } = f.geometry;

            let points: number[][][] = [];
            if (type === 'MultiPolygon') {
            }

            if (!isNumber(get(coordinates, [0, 0, 0]))) {
                points.push(...flatten(coordinates));
            }

            for (let i = 0; i < points.length; i++) {
                rockMeshoptions.paths = [];
                if (points[i].length > 20) {
                    for (let ii = 0; ii < points[i].length; ii++) {
                        const [x, y] = points[i][ii];
                        rockMeshoptions.paths.push({
                            vector3: [x, 0, y * -1],
                            radius: 1,
                            segments: 0,
                            scale: { x: 0.1, y: 0.1 },
                            name: ""
                        });
                    }
                }

                // 创建岩石层对象
                const rockMesh = new ExtrudeMesh(rockMeshoptions);
                rockMesh.material = this.rockMaterial;
                rockMesh.userData = { cursor: "pointer", name, adcode };

                autorun(() => {
                    const { areaCode } = siChuanMap3DStore;
                    const visible = [510000, adcode].includes(areaCode);
                    rockMesh.visible = visible;
                });

                rockMesh.name = name;
                // const box3 = new Box3();
                // const center = new Vector3();
                // box3.setFromObject(rockMesh);
                // box3.getCenter(center);
                // rockMesh.geometry.translate(0, 0, 0);
                rockGroup.add(rockMesh);
            }
        });

        // threeUtils.scaleTo(rockGroup, 10);
        threeUtils.centerObject3D(rockGroup);

        autorun(() => {
            const { areaCode } = siChuanMap3DStore;
            const visible = [510000].includes(areaCode);
            rockGroup.visible = visible;
        });

        this.add(rockGroup);

        // rockGroup.position.set(0, 0, 0);
        // rockGroup.scale.set(1, 1, 1);
        return rockGroup;
    })();

    // 线材质
    lineMaterial = new LineMaterial({
        color: 0x84e0f6,
        linewidth: 0.002,
        // worldUnits: true,
        vertexColors: false,
        alphaToCoverage: false
    });

    // 地图的边界线
    mapLine = (() => {
        const mapLine = new Group();

        geometryJSON.features.map((f, index) => {
            const { adcode, name } = f.properties;
            let { coordinates, type } = f.geometry;
            // let points = f.geometry.coordinates;
            let points: number[][][] = [];
            if (type === 'MultiPolygon') {
            }

            if (!isNumber(get(coordinates, [0, 0, 0]))) {
                points.push(...flatten(coordinates));
            }

            for (let i = 0; i < points.length; i++) {
                const lineGeometry = new LineGeometry();
                const positions = [];
                for (let ii = 0; ii < points[i].length; ii++) {
                    const [x, y] = points[i][ii];
                    positions.push(x, 0, y * -1);
                }
                lineGeometry.setPositions(positions);

                const line2 = new Line2(lineGeometry, this.lineMaterial);
                line2.name = name;

                autorun(() => {
                    const { areaCode } = siChuanMap3DStore;
                    const visible = [510000, adcode].includes(areaCode);
                    line2.visible = visible;
                });

                mapLine.add(line2);
            }
        });

        // 计算每个模型的uv的值, 并移动到中心点
        const box3 = new Box3();
        const center = new Vector3();
        box3.setFromObject(mapLine);
        box3.getCenter(center);
        mapLine.traverse(line => {
            if ((line as Line2).isLine2) {
                (line as Line2).geometry.translate(-center.x, -center.y, -center.z);
            }
        });

        autorun(() => {
            // const { areaCode } = siChuanMap3DStore;
            // const visible = [510000].includes(areaCode);
            // mapLine.visible = visible;
        });

        mapLine.position.set(0, 0.51, 0);
        this.add(mapLine);

        return mapLine;
    })();

    // 地区标签的模型组
    areaLableGroup = (() => {
        const areaLableGroup = new class AreaLableGroup extends Group { }();

        const data = [
            { areaName: "成都市", areaCode: 510100, iconColor: "orange", position: new Vector3(0.9, 0.5, -0.63) },
            { areaName: "甘孜", areaCode: 513300, iconColor: "", position: new Vector3(-2.821, 0.5, -0.6) },
            { areaName: "凉山", areaCode: 513400, iconColor: "", position: new Vector3(-0.7, 0.5, 2.3) },
            { areaName: "泸州", areaCode: 510500, iconColor: "", position: new Vector3(2.828, 0.5, 2.26) },
            { areaName: "宜宾", areaCode: 511500, iconColor: "", position: new Vector3(1.78, 0.5, 1.557) },
            { areaName: "乐山", areaCode: 511100, iconColor: "", position: new Vector3(0.579, 0.5, 0.936) },
            { areaName: "达州", areaCode: 511700, iconColor: "", position: new Vector3(4.865, 0.5, -1.486) },
            { areaName: "南充", areaCode: 511300, iconColor: "", position: new Vector3(3.292, 0.5, -1.097) },
            { areaName: "阿坝", areaCode: 513200, iconColor: "", position: new Vector3(-0.516, 0.5, -2.093) },
            { areaName: "雅安", areaCode: 511800, iconColor: "", position: new Vector3(-0.322, 0.5, 0.142) },
            { areaName: "广元", areaCode: 510800, iconColor: "", position: new Vector3(2.856, 0.5, -2.141) },

        ];

        data.map(l => {
            const areaName = (
                l.iconColor ?
                    new AreaName3(l.areaName, 16, "#fff", l.iconColor as "red" | "orange" | "blue")
                    :
                    new AreaName1(l.areaName, 16, "#fff")
            );
            areaName.position.copy(l.position);
            autorun(() => {
                const { areaCode } = siChuanMap3DStore;
                const visible = [510000, l.areaCode].includes(areaCode);
                areaName.visible = visible;
            });

            areaLableGroup.add(areaName);
        });

        autorun(() => {
            const { areaCode } = siChuanMap3DStore;
            const visible = [510000].includes(areaCode);
            areaLableGroup.visible = visible;
        });

        this.add(areaLableGroup);
        return areaLableGroup;
    })();

    // 地区统计标签
    areaStatisticss = (() => {
        const areaStatisticss = new Group();

        const lablePositions = [
            { name: "甘孜藏族自治州", position: new Vector3(-2.026, 0.5, 0.368) },
            { name: "凉山彝族自治州", position: new Vector3(-1.433, 0.5, 2.308) },
            { name: "宜宾市", position: new Vector3(1.819, 0.5, 1.904) },
            { name: "泸州市", position: new Vector3(2.662, 0.5, 1.313) },
            { name: "乐山市", position: new Vector3(0.559, 0.5, 1.177) },
            { name: "雅安市", position: new Vector3(-0.347, 0.5, 0.474) },
            { name: "阿坝藏族羌族自治州", position: new Vector3(-0.46, 0.5, -1.617) },
            { name: "南充市", position: new Vector3(3.253, 0.5, -0.818) },
            { name: "达州市", position: new Vector3(4.663, 0.5, -1.08) },
            { name: "巴中市", position: new Vector3(4.07, 0.5, -1.886) },
            { name: "广元市", position: new Vector3(2.847, 0.5, -1.975) },
            { name: "绵阳市", position: new Vector3(1.867, 0.5, -1.658) },
            { name: "成都市", position: new Vector3(1.365, 0.5, -0.35) },
            { name: "资阳市", position: new Vector3(2.159, 0.5, 0.048) },

        ]

        autorun(() => {
            const sichuanMapData = toJS(doubtfulSituationStore.sichuan_map_data);
            areaStatisticss.children.length = 0;
            for (let i in sichuanMapData) {
                const { name, total, value } = sichuanMapData[i];
                const lablePosition = lablePositions.find(l => l.name === name);
                if (lablePosition) {
                    const ringSprite = new RingSprite(total, value);
                    ringSprite.position.copy(lablePosition.position);
                    areaStatisticss.add(ringSprite);
                } else {
                    // console.log(name);
                }
            }
        });

        autorun(() => {
            const { areaCode } = siChuanMap3DStore;
            areaStatisticss.visible = (510000 === areaCode);
        });

        this.add(areaStatisticss);
        return areaStatisticss;
    })();

    //医院标签
    hospitalLables = (() => {
        const hospitalLables = new Group();

        // 成都机构的坐标位置
        const chengdu_points: Array<Vector3> = [
            new Vector3(0.26, 0.5, -0.547),
            new Vector3(0.422, 0.5, -0.403),
            new Vector3(0.498, 0.5, -0.151),
            new Vector3(0.709, 0.5, -0.344),
            new Vector3(1.089, 0.5, -0.55),
            new Vector3(1.151, 0.5, -0.267),
            new Vector3(1.38, 0.5, -0.621),
            new Vector3(1.627, 0.5, -0.57),
            new Vector3(1.528, 0.5, -0.188),
            new Vector3(1.806, 0.5, -0.259),
        ];

        // 凉山机构的坐标位置
        const liangshan_points: Array<Vector3> = [
            new Vector3(-2.186, 0.521, 1.97),
            new Vector3(-1.71, 0.521, 2.696),
            new Vector3(-1.3, 0.521, 2.081),
            new Vector3(-0.65, 0.521, 1.658),
            new Vector3(-0.089, 0.521, 1.642),
            new Vector3(-0.473, 0.520, 2.555),
            new Vector3(0.303, 0.521, 2.377),
            new Vector3(-0.699, 0.521, 3.66),
            new Vector3(-0.131, 0.521, 3.616),
        ];

        // 阿坝机构的坐标位置
        const aba_points: Array<Vector3> = [
            new Vector3(-1.96, 0.5, -2.188),
            new Vector3(-1.396, 0.5, -2.399),
            new Vector3(-0.672, 0.5, -2.784),
            new Vector3(0.213, 0.5, -2.921),
            new Vector3(0.996, 0.5, -3.001),
            new Vector3(-1.411, 0.5, -1.593),
            new Vector3(-0.751, 0.5, -1.773),
            new Vector3(-0.086, 0.5, -2.025),
            new Vector3(0.681, 0.5, -2.294),
            new Vector3(0.018, 0.5, -1.351),
        ];

        // 甘孜机构的坐标位置
        const gazi_points: Array<Vector3> = [
            new Vector3(-4.826, 0.5, -3.208),
            new Vector3(-4.345, 0.5, -2.079),
            new Vector3(-3.102, 0.5, -1.961),
            new Vector3(-2.289, 0.5, -1.329),
            new Vector3(-3.853, 0.5, -0.764),
            new Vector3(-2.767, 0.5, -0.07),
            new Vector3(-1.667, 0.5, -0.083),
            new Vector3(-2.963, 0.5, 0.683),
            new Vector3(-1.471, 0.5, 0.58),
            new Vector3(-1.321, 0.5, 1.276),
        ];

        autorun(() => {
            const { areaCode } = siChuanMap3DStore;
            const mapData = toJS(doubtfulSituationStore.map_data);
            hospitalLables.children.length = 0;

            mapData.map((d: any, i: number) => {
                const areaName = new Ball(d.name.replace(/([(|(])/, "\n$1"));
                areaName.name = d.name;
                areaName.addEventListener("click", () => {
                    doubtfulSituationStore.setActiveMap(d);
                });

                switch (areaCode) {
                    // 成都视角
                    case 510100:
                        areaName.position.copy(chengdu_points[i % chengdu_points.length]);
                        break;
                    // 凉山视角
                    case 513400:
                        areaName.position.copy(liangshan_points[i % liangshan_points.length]);
                        break;
                    // 甘孜视角
                    case 513300:
                        areaName.position.copy(gazi_points[i % gazi_points.length]);
                        break;
                    // 阿坝视角
                    case 513200:
                        areaName.position.copy(aba_points[i % aba_points.length]);
                        break;

                    default:
                        break;
                }

                hospitalLables.add(areaName);
            });

        });

        autorun(() => {
            const { activeMapData } = doubtfulSituationStore;
            hospitalLables.children.map(o => {
                (o as Ball).isActive(o.name === activeMapData.name);
            })

        });

        autorun(() => {
            const { areaCode } = siChuanMap3DStore;
            hospitalLables.visible = (510000 !== areaCode);
        });

        this.add(hospitalLables);
        return hospitalLables;
    })();



}
